﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using backoffice.Data;

namespace backoffice.Business
{
    public class BusinessNutrient
    {
        #region Create
        public static void createNutrient(Nutrient n)
        {
            try
            {
                dataNutrient.createNutrient(n);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error creating nutrient");
            }
        }

        public static void createNutrient(Plant p,
                                          float water, float energy, float fat, float starch, float sugar, float fibre,
                                          float na, float k, float ca, float fe,
                                          float vitamine, float vitaminb1, float vitaminb2, float vitaminc, float protein,
                                          float carotene, float carbohydrate, float fibre_NSP, float folate)
        {
            try
            {
                Nutrient n = new Nutrient();
                n.PlantID = p.PlantID;
                n.Water = water;
                n.Energy = energy;
                n.Fat = fat;
                n.Starch = starch;
                n.Sugar = sugar;
                n.Fibre = fibre;
                n.Na = na;
                n.K = k;
                n.Ca = ca;
                n.Fe = fe;
                n.VitaminE = vitamine;
                n.VitaminB1 = vitaminb1;
                n.VitaminB2 = vitaminb2;
                n.VitaminC = vitaminc;
                n.Protein = protein;
                n.Carotene = carotene;
                n.Carbohydrate = carbohydrate;
                n.Fibre_NSP = fibre_NSP;
                n.Folate = folate;

                dataNutrient.createNutrient(n);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error creating nutrient");
            }
        }
        #endregion

        #region Get
        public static Nutrient getNutrient(Guid guid)
        {
            try
            {
                return dataNutrient.getNutrient(guid);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error getting nutrient");
            }
        }

        public static Nutrient getNutrientByPlant(Plant p)
        {
            try
            {
                return dataNutrient.getNutrient(p.PlantID);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error getting nutrient by plant");
            }
        }
        #endregion

        #region Set
        public static Boolean changeNutrient(Nutrient n)
        {
            try
            {
                return dataNutrient.changeNutrient(n);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error changing nutrient");
            }
        }
        #endregion

        #region Delete
        public static Boolean deleteNutrient(Nutrient n)
        {
            try
            {
                return dataNutrient.deleteNutrient(n);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error deleting nutrient");
            }
        }
        #endregion
    }
}
